import java.util.List;

public class Candidate {
	public static final int EVENT_LIST_SIZE = 3;
	private int numberOfEvents;

	private Event[] events;

	public Candidate() {
		this.events = new Event[Candidate.EVENT_LIST_SIZE];
		this.numberOfEvents = 0;
	}

	public boolean addEvent(Event e) {
		if (this.numberOfEvents < Candidate.EVENT_LIST_SIZE) {
			this.events[this.numberOfEvents++] = e;
			return true;
		}

		return false;
	}

	public Event[] getEvents() {
		return this.events;
	}

	/**
	 * Returns the smallest distance between this candidate and all testCases
	 * given
	 * 
	 * @param executedTestCases
	 * @return
	 */
	public int smallestDistance(List<TestCase> testCases) {
		int distance = Candidate.EVENT_LIST_SIZE; // the maximum distance
		for (TestCase testCase : testCases) {
			int d = Levenshtein
					.calculateDistance(testCase.getCandidate(), this);
			if (d < distance) {
				distance = d;
			}
		}
		return distance;
	}

	public String toString() {
		String s = "";
		for (Event e : this.events) {
			s += e.getCode();
		}
		return s;
	}
}
